package it.avantsoft.ls.peer.command;

import it.avantsoft.ls.peer.PeerHandler;

public class ConnectToGLCommand extends PeerCommand {
    private String childId;
    private String groupLeaderHost;
    private int groupLeaderListeningPort;

    public ConnectToGLCommand(PeerHandler peerHandler, String childId, String groupLeaderHost, int groupLeaderListeningPort) {
        super(peerHandler);
        this.childId = childId;
        this.groupLeaderHost = groupLeaderHost;
        this.groupLeaderListeningPort = groupLeaderListeningPort;
    }

    public void execute() {
        getPeer().setPeerId(childId);
        getPeer().connectToGL(groupLeaderHost, groupLeaderListeningPort);
    }

    public String toString() {
        return "ConnectToGLCommand{" +
                "childId='" + childId + '\'' +
                ", groupLeaderHost='" + groupLeaderHost + '\'' +
                ", groupLeaderListeningPort=" + groupLeaderListeningPort +
                '}';
    }
}
